<template>
	<view>

		<view v-for="(item,index) in newslist" :key="index" class="news" @click="goNews(item.id)">
			<image src="../../static/imgs/bg.png" mode="" class="news-img"></image>
			<view class="right">
				<view class="news-title">{{item.title}}</view>
				<view class="right-bt">
					<view class="">
						<!-- <u-icon name="eye" color="#999" size="10"></u-icon>
							<text>323阅读</text> -->
					</view>
					<view class="">
						<u-icon name="clock" color="#999" size="10"></u-icon>
						<text>{{$u.timeFormat(item.createtime, 'yyyy-mm-dd')}}</text>
					</view>
				</view>
			</view>
		</view>


	</view>
</template>

<script>
	import {
		getNewsList
	} from '@/config/api.js'
	export default {
		data() {
			return {
				newslist: []
			};
		},
		onLoad() {
			this.getList()
		},
		methods: {
			async getList() {
				uni.showLoading({
					title: '加载中'
				})
				const res = await getNewsList()
				uni.hideLoading()
				if (res.code == 1) {
					this.newslist = res.data
				} else {
					uni.showToast({
						title: res.msg,
						icon: 'none'
					})
				}
			},
			// 去新闻详情
			goNews(id) {
				uni.navigateTo({
					url: './news?id=' + id
				})
			},

		}
	}
</script>
<style>
	page {
		background-color: #f8f8f8;

	}
</style>

<style lang="scss">
	.news {
		background-color: #fff;
		margin: 20rpx 20rpx 10rpx;
		border-radius: 20rpx;
		display: flex;
		align-items: center;
		padding: 30rpx 20rpx;
		border-bottom: 1px solid #f8f8f8;

		&:last-child {
			border: 0;
		}

		.news-img {
			width: 200rpx;
			height: 120rpx;
			border-radius: 10rpx;
		}

		.right {
			flex: 1;
			overflow: hidden;
			margin-left: 20rpx;
			height: 120rpx;
			display: flex;
			justify-content: space-between;
			flex-direction: column;

			.news-title {
				font-size: 28rpx;
				color: #333;
			}

			.right-bt {
				display: flex;
				align-items: center;
				justify-content: space-between;
				color: #999;
				font-size: 20rpx;

				view {
					display: flex;
					align-items: center;
				}
			}
		}
	}
</style>